﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services.Description;
using System.Web.UI;
using System.Web.UI.WebControls;
using DBHelper;
using SME.Food.Surperise.BLL;

namespace SME.Food.Tricon.Web.AdminJS
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CookieValues cook = new CookieValues();
            string usename  = Request.Form["UserName"];
            string password = Request.Form["PassWord"];
            Bas_User_BLL bll = new Bas_User_BLL();
            if ( string.IsNullOrEmpty(usename) ||string.IsNullOrEmpty(password))
            {
                Response.Write("<script> href='javascript:;';alertMsg.error('用户名或密码不能为空！'); </script>"); 
            }
            else
            {
                string sql =string.Format("select * from Bas_User where User_Name='" + usename + "' and User_PassWord='" + password +"'");
                DataTable dt = DbHelperSQL.Query(sql).Tables[0];
                if (dt.Rows.Count < 0)
                {
                    Response.Write("<script> href='javascript:;';alertMsg.error('用户名或密码输入不正确！'); </script>");
                }
                else
                {
                    SetCookie(dt);
                  Response.Redirect("index.aspx");
                }
            }
        }

        public void SetCookie(DataTable dt)
        {

            HttpCookie cookie = new HttpCookie("MyCook");//初使化并设置Cookie的名称  
            DateTime mdtm = DateTime.Now;
            TimeSpan ts = new TimeSpan(1, 0, 0, 0, 0);//过期时间为1分钟  
            cookie.Expires = mdtm.Add(ts);//设置过期时间  
            cookie.Values.Add("User_No", dt.Rows[0]["User_No"].ToString());
            cookie.Values.Add("User_Name", dt.Rows[0]["User_Name"].ToString());
            cookie.Values.Add("User_PassWord", dt.Rows[0]["User_PassWord"].ToString());
            cookie.Values.Add("Mem_No", dt.Rows[0]["Mem_No"].ToString());
            cookie.Values.Add("Mem_Power", dt.Rows[0]["Mem_Power"].ToString());
            HttpCookie coo = Request.Cookies["MyCook"];
            Response.AppendCookie(cookie);
             coo = Request.Cookies["MyCook"];
        }
    }

   
}